package activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.evaluity.R;

import views.DegreeAdapter;
import views.UniversityAdapter;

import data.DATA_Helper;
import logic.Degree;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class DegreeList extends ListActivity {
	private HashMap<Integer, Degree> degreeMap = new HashMap<Integer, Degree>();
	public static final String EXTRA_UNI_ID = "id_uni";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_degree_list);
		
		Intent i = getIntent();
		String uniId = i.getStringExtra(EXTRA_UNI_ID);
		List<Degree> degrees = DATA_Helper.getDegreesByUniversity(uniId);
		List<String> degNames = new ArrayList<String>();
		
		for (int i1 = 0; i1 < degrees.size(); i1++) {
			degNames.add(degrees.get(i1).getName());
			degreeMap.put(i1, degrees.get(i1));
		}
		//ArrayAdapter<String> degreeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, degNames);
		//setListAdapter(degreeAdapter);
		setListAdapter(new DegreeAdapter(this, degrees));
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Degree d = degreeMap.get(position);
		
		Intent i = new Intent(this, CourseList.class);
		i.putExtra(CourseList.EXTRA_DEGREE_ID, d.getId());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.degree_list, menu);
		return true;
	}

}
